// 根据配置挂载axios实例
import { RequestConfigInterface, RequestDefierConfig } from './service.config';
import Axios from './Axios';
import { isTypeOf } from './utils';
export default class Request {
  constructor(RequestConfig?: RequestConfigInterface[] | RequestConfigInterface) {
    this.loadAxios(RequestConfig); // 初始化声明周期
  }
  public loadAxios(RequestConfig) {
    if (isTypeOf(RequestConfig, 'Array')) {
      for (const config of RequestConfig) {
        this.getAxios(config);
      }
    } else if (isTypeOf(RequestConfig, 'Object')) {
      this.getAxios(RequestConfig);
    } else {
      this.getAxios({});
    }
  }
  public getAxios(config) {
    const axiosConfig = {...RequestDefierConfig, ...config};
    this[config.name] = new Axios(axiosConfig).createAxios();
  }
}

